//
//  LYFTabBarViewController.m
//  LYFWB
//
//  Created by lyf on 16/6/30.
//  Copyright © 2016年 lyf. All rights reserved.
//

#import "LYFTabBarViewController.h"
#import "LYFHomeController.h"
#import "LYFMessageController.h"
#import "LYFPublicController.h"
#import "LYFDisCoverController.h"
#import "LYFProfileController.h"


#import "LYFTabBar.h"
@interface LYFTabBarViewController ()

@end

@implementation LYFTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addOneChildVcClass:[LYFHomeController class] title:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];
    [self addOneChildVcClass:[LYFMessageController class] title:@"消息" image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];
    [self addOneChildVcClass:[LYFDisCoverController class] title:@"发现" image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];
    [self addOneChildVcClass:[LYFProfileController class] title:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
    
    //注册定义的tabBar
    [self setValue:[[LYFTabBar alloc]init] forKeyPath:@"tabBar"];
}

/**
 * 添加一个子控制器
 * @param vc : 子控制器
 * @param title : 标题
 * @param image : 图片
 * @param selectedImage : 选中的图片
 */
- (void)addOneChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    [vc.tabBarItem setTitleTextAttributes:@{
                                            NSForegroundColorAttributeName : [UIColor orangeColor]
                                            } forState:UIControlStateSelected];
    
    // 控制tabbar每个标签的文字
    //    vc.tabBarItem.title = title;
    // 控制navigationBar的文字
    //    vc.navigationItem.title = title;
    // 同时设置tabbar每个标签的文字 和 navigationBar的文字
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    vc.view.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:1.0];
    
    // 包装一个导航控制器后,再成为tabbar的子控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}
/**
 * 添加一个子控制器
 * @param vcClass : 子控制器的类名
 * @param title : 标题
 * @param image : 图片
 * @param selectedImage : 选中的图片
 */
- (void)addOneChildVcClass:(Class)vcClass title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    UIViewController *vc = [[vcClass alloc] init];
    [self addOneChildVc:vc title:title image:image selectedImage:selectedImage];
}


@end
